package com.ljq.controller;

//import com.ljq.service.impl.ScoketClient;
import com.ljq.websockets.WebSocket;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("/websocket")
public class WebSocketClientController {

//    @Autowired
//    private ScoketClient webScoketClient;


    @Autowired
    WebSocket webSocket;

    /**
     * 发送消息JSON
     *{
     *     "message" :" hello,我是wxy，我想和你做朋友",   message： 消息内容
     *     "userId":"wxy",                             userId：当前用户id
     *     "to":"ljq"                                  to：发给谁的用户的id
     * }
     */

    @GetMapping("/sendTo")
    public String sendTo(@RequestParam("userId") String userId, @RequestParam("msg") String msg) throws IOException {

        webSocket.sendMessageTo(msg,userId);

        return "推送成功";
    }

    @GetMapping("/sendAll")
    public String sendAll(@RequestParam("msg") String msg) throws IOException {

        String fromUserId="system";//其实没用上
        webSocket.sendMessageAll(msg,fromUserId);

        return "推送成功";
    }


//    @GetMapping("/sendMessage")
//    public String sendMessage(String message){
//        webScoketClient.groupSending(message);
//        return message;
//    }
//
//    @GetMapping("/sendMessageOne")
//    public String sendMessageOne(String userId,String message){
//        webScoketClient.appointSending(userId,message);
//        return message;
//    }


}
